const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {
    private _material: cc.MaterialVariant;
    private pos_x = 0;
    private pos_y = 0;

    onLoad() {
        if (this.node.getComponent(cc.Label)) {
            this._material = this.node.getComponent(cc.Label).getMaterial(0);
        } else if (this.node.getComponent(cc.Sprite)) {
            this._material = this.node.getComponent(cc.Sprite).getMaterial(0);
        }
        this.node.on(cc.Node.EventType.TOUCH_MOVE, (event: cc.Event.EventTouch) => {
            this.pos_x = event.getLocationX();
            this.pos_y = event.getLocationY();

            this._material.setProperty('pos_x', this.pos_x);
            this._material.setProperty('pos_y', this.pos_y);
        });
    }

    start() {}
    // update (dt) {}
}
